package com.suixun.controller.credits;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.authority.controller.BaseManager;
import com.suixun.entity.form.credits.company.OrderPageForm;
import com.suixun.service.credits.OrderService;
import com.suixun.util.Constant;
import com.suixun.vo.credits.ResponseVo;

/**
 * 积分订单
 * 
 * @author yh
 * @date 2017年12月18日
 */
@RestController
@RequestMapping(value = "/credits/order")
public class OrderController extends BaseManager {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询积分订单列表
     * 
     * @param param
     * @return
     */
    @RequestMapping(value = "/find_page.json", method = RequestMethod.GET)
    public Object findPage(OrderPageForm param) {

        /*if (!checkRight()) {
            return fail(Constant.Authority.CHECK_FALSE);
        }*/

        try {
            if (!param.verify()) {
                return fail(Constant.PARAM_ERROR);
            }
            return success(orderService.findPage(param));
        } catch (Exception e) {
            logger("OrderController findPage:" + e.getMessage(), e);
            return fail(Constant.EXCEPTION.OPERATE_FAIL);
        }
    }

    /**
     * 积分订单详情
     * 
     * @param id
     *            积分订单id
     * @return
     */
    @RequestMapping(value = "/find_details.json", method = RequestMethod.GET)
    public Object findDetails(@RequestParam("id") Integer id) {

        /*if (!checkRight()) {
            return fail(Constant.Authority.CHECK_FALSE);
        }*/

        try {
            if (id == null) {
                return fail(Constant.PARAM_ERROR);
            }
            return success(new ResponseVo<>(orderService.findDetails(id)));
        } catch (Exception e) {
            logger("OrderController findDetails:" + e.getMessage(), e);
            return fail(Constant.EXCEPTION.OPERATE_FAIL);
        }
    }

}
